<?php
// +----------------------------------------------------------------------
// | 简易CMS
// +----------------------------------------------------------------------
// | Copyright (C) 2010 Hoping Software Studio.
// +----------------------------------------------------------------------
// | Version $Id$
// +----------------------------------------------------------------------
namespace app\admin\controller;

/**
 * 后台首页控制器
 * @author IT果农 <htmambo@163.com>
 */
class Index extends AdminController {

    /**
     * 后台首页
     * @author IT果农 <htmambo@163.com>
     */
    public function index(){
		C('SHOW_PAGE_TRACE', false);
        $this->meta_title = '管理首页';
        return $this->fetch();
    }

    /**
     * 后台用户登录
     * @author IT果农 <htmambo@163.com>
     */
    public function login($username = null, $password = null, $verify = null){
        if(IS_POST){
            /* 检测验证码 TODO: */
            $result = check_verify($verify);
            if($result<1){
                $this->error('验证码输入错误！'.$result);
            }
            $Member = D('Member');
            if($Member->login($username, $password)){ //登录用户
                //TODO:跳转到登录前页面
                $this->success('登录成功！', U('Index/index'));
            } else {
                $this->error($Member->getError());
            }
        } else {
            if(is_login()){
                $this->redirect('Index/index');
            }else{
                return $this->fetch();
            }
        }
    }

    /* 退出登录 */
    public function logout(){
        if(is_login()){
            D('Member')->logout();
            session('[destroy]');
            $this->success('退出成功！', U('login'));
        } else {
            $this->redirect('login');
        }
    }

    public function verify(){
        $verify = new \CMS\Verify(array('fontSize'=>25, 'length'=>5, 'imageH'=>32, 'imageW' => 150));
        $verify->entry(1);
    }

}
